/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"7F053BB7-8BBA-4297-B4C1-7F4621EF5135",variableType:4}
 */
var fcodigo;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"9AD572E0-E6FC-46E7-90B7-87071DDD6819"}
 */
var fdescripcion = null;

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"24286A7D-B126-40BD-967B-1795E78CA468"}
 */
function onDataChange_codigo(oldValue, newValue, event) {
	if (controller.getSelectedIndex() == 1 && globals.gEstadoAbm == 1)
	{
		elements.descripcion.requestFocus()
		return true
	}
	else
	{
		elements.descripcion.requestFocus()
		codigo = oldValue
		return true
	}
}

/**
 * @properties={typeid:24,uuid:"AA34C307-8E49-475B-92B3-BD179AB44C38"}
 */
function validar() {
	controller.setSelectedIndex(1)
	if (globals.gEstadoAbm == 1)
	{
		var $sql = 'SELECT codigo FROM leyendas WHERE codigo = ? AND empresa = ?'
		var $args = [codigo, globals.gUservID]
		var $ds = databaseManager.getDataSetByQuery('contable',$sql,$args,-1)
		if ($ds.getMaxRowIndex() != 0) 
		{		
			return [false, false, "El código ingresado ya existe"]
		}
	}
	return [true]
}

/**
 * @properties={typeid:24,uuid:"1309B22C-F497-46D2-AA9C-DB2E454C060C"}
 */
function imprimir()
{
	//forms.leyendas_impresion.controller.showPrintPreview()
	jasper('impresion')
}

/**
 * @properties={typeid:24,uuid:"C9320807-8753-480E-865C-73FAE8A13677"}
 */
function pdf()
{
	//globals.metodoPdf('leyendas_impresion','leyendas - '+ globals.glegajo,true)
	jasper('pdf')
}

/**
 * @properties={typeid:24,uuid:"F4EC2E2C-2146-4031-B23C-4ACFD5381195"}
 */
function xls()
{
	jasper('xls')
}

/**
 * @properties={typeid:24,uuid:"DAA0F7FB-69A5-40FB-8752-8984C056F79F"}
 */
function csv()
{
	jasper('csv')
}

/**
 * @param {String} tipo
 * 
 * @properties={typeid:24,uuid:"6AAAAF5A-ACD0-42AE-8998-62AEAD050D15"}
 */
function jasper(tipo)
{
	var $params = {
		userv: usuarios_to_uservs.razon_social
	}
	
	globals.metodoJasper(tipo,'contable/leyendas.jasper','Leyendas',foundset,$params)
}